﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Net;
using System.Net.Sockets;

namespace zszs
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        //请求
        /// <summary>
        /// 请求
        /// </summary>
        private HttpClient httpClient;
        //数
        /// <summary>
        /// 数
        /// </summary>
        private VoteCount voteCount;

        //QQ相关 信息
        /// <summary>
        /// QQ相关 信息
        /// </summary>
        private QQUser qquser;

        //是否登陆成功
        /// <summary>
        /// 是否登陆成功
        /// </summary>
        private bool isLoginSuc = false;

        private ValidateVersion vv;

        //改变状态
        /// <summary>
        /// 改变状态
        /// </summary>
        private event ChangeState eventChangeTab;

        //需要验证码事件
        /// <summary>
        /// 需要验证码
        /// </summary>
        private event NeedImage eventNeedImage;

        private const string SPECIAL_PWD = "feiazi...?";

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //httpClient.UseDefaultCredentials
            this.Text = " 战秀家族自动审核软件";
            this.gbQQQzone.Visible = true;
            this.gbCode.Visible = false;
            voteCount = new VoteCount();
            vv = new ValidateVersion();
            qquser = new QQUser();
            qquser.NiceNamePrefix = "戰show.";
            qquser.SpacenamePrefix = "卍、当红世家★╮戰show.．";
            vv.Days = 5;
            vv.beginDateTime = new DateTime(2011, 1, 17);
            this.eventNeedImage += new NeedImage(FrmMain_eventNeedImage);
            this.eventChangeTab += new ChangeState(FrmMain_eventChangeTab);
            //GetTime();
            Thread th = new Thread( new ThreadStart(GetTime));
            th.Start();

        }
        public void GetTime()
        {
            SNTPTimeClient client = new SNTPTimeClient("210.72.145.44", "123");
            client.Connect();
            string strTest = client.ToString();
            //this.SetText(strTest);
            
        }
        byte[] NTPData = null;
        //public void AA()
        //{
        //    IPAddress hostadd = IPAddress.Parse("");

        //    IPEndPoint EPhost = new IPEndPoint(hostadd, Convert.ToInt32("123"));

        //    UdpClient TimeSocket = new UdpClient();

        //    TimeSocket.Connect(EPhost);

        //    NTPData[0] = 0x1B;
 
        //    for (int i = 1; i < 48; i++)
        //    {

        //        NTPData[i] = 0;

        //    }
 
        //    TransmitTimestamp = DateTime.Now;
            
        //    TimeSocket.Send(NTPData, NTPData.Length);

        //    NTPData = TimeSocket.Receive(ref EPhost);

        //    if (!IsResponseValid())
        //    {
        //        throw new Exception("Invalid response from " + TimeServer);
        //    }

        //}
        //public bool IsResponseValid()
        //{

        //    if (NTPData.Length < NTPDataLength || Mode != _Mode.Server)
        //    {
        //        return false;
        //    }
        //    else
        //    {
        //        return true;
        //    }

        //}

        //加入家族
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //AA();
            int validate = vv.Validate();
            validate = 1;
            if (validate == -1)
            {
                MessageBox.Show("试用版本已到期,请联系作者获取正版。QQ:605064709");
                Application.Exit();
            }
            else if (validate == 0)
            {

                MessageBox.Show("网络连接异常,请重试");
                return;
            }
            if (this.txtNiceName.Text == "")
            {
                MessageBox.Show("輸嚸內傛ぬ卟ぬo(╯□╰)o", @"~\(≧▽≦)/~", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //卍、当红世家★╮
            if (this.txtNiceName.Text.Contains(SPECIAL_PWD))
            {
                qquser.Nickname = this.txtNiceName.Text.TrimStart(SPECIAL_PWD.ToCharArray());
            }
            else
            {
                qquser.Nickname = qquser.NiceNamePrefix + this.txtNiceName.Text;
                int length = Length(qquser.Nickname);
            }
            qquser.Spacename = qquser.SpacenamePrefix+this.txtNiceName.Text;
            //qquser.Signature = qquser.Nickname + "签名档。";
            qquser.Con = "网络第一口碑家族.戰秀家族横空出世。审核「33934530」";
            qquser.UpdateState = UpdateState.昵称;
            httpClient = new HttpClient(new Uri(VoteUrl.ADRESS_QZONE));
            httpClient.Cookies.Capacity = 300;
            httpClient.Cookies.PerDomainCapacity = 200;

            FrmLogin fm = new FrmLogin(this.httpClient);
            fm.loginEvent += new LoginCallback(fm_loginEvent);
            fm.setTextEvent += new SetTextCallback(fm_setTextEvent);
            DialogResult dr = fm.ShowDialog();
            if (isLoginSuc)
            {
                this.SetText(qquser.QQAccount + "登陆成功。");
                this.gbQQQzone.Visible = false;
                this.gbCode.Visible = true;
                Submit();
            }
            else
            {
                this.SetText("未登陆!");
            }
        }

        //图片 点击 换图片
        private void pbImage_Click(object sender, EventArgs e)
        {
            ImageCode();
        }

        // 输入验证码 进行提交
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Submit();
        }

        #region FrmLogin类 的事件 执行
        void fm_setTextEvent(string text)
        {
            this.SetText(text);
        }

        void fm_loginEvent(bool isLoginSuc, string qqAccount)
        {
            this.isLoginSuc = isLoginSuc;
            qquser.QQAccount = qqAccount;
        }
        #endregion

        // 给值
        /// <summary>
        ///  给值
        /// </summary>
        /// <param name="text"></param>
        private void SetText(string text)
        {
            if (this.rtbResult.InvokeRequired)
            {
                SetTextCallback set = new SetTextCallback(SetText);
                this.Invoke(set, text);
            }
            else
            {
                this.rtbResult.AppendText(string.Format("{0}.{1} {2}{3}", voteCount.NumberCount++, DateTime.Now, text, Environment.NewLine));
                this.rtbResult.ScrollToCaret();
                if (voteCount.NumberCount % 20 == 0)
                {
                    Log();
                }
            }
        }

        #region 当前类 事件执行

        /// <summary>
        /// 改变状态
        /// </summary>
        /// <param name="b"></param>
        private void ChangeSubmitButtonState(bool b)
        {
            if (this.btnSubmit.InvokeRequired)
            {
                ChangeState cs = new ChangeState(ChangeSubmitButtonState);
                this.Invoke(cs, b);
            }
            else
            {
                this.btnSubmit.Enabled = b;
            }
        }

        /// <summary>
        /// 改变状态
        /// </summary>
        /// <param name="b"></param>
        private void ChangeGgbCodeCodeState(bool b)
        {
            if (this.gbCode.InvokeRequired)
            {
                ChangeState cs = new ChangeState(ChangeGgbCodeCodeState);
                this.Invoke(cs, b);
            }
            else
            {
                this.gbCode.Visible = b;
            }
        }
        /// <summary>
        /// 改变状态
        /// </summary>
        /// <param name="b"></param>
        private void ChangeGbQQQzoneState(bool b)
        {
            if (this.gbQQQzone.InvokeRequired)
            {
                ChangeState cs = new ChangeState(ChangeGbQQQzoneState);
                this.Invoke(cs, b);
            }
            else
            {
                this.gbQQQzone.Visible = b;
            }
        }

        void FrmMain_eventChangeTab(bool b)
        {
            this.ChangeGbQQQzoneState(true);
            this.ChangeGgbCodeCodeState(false);
        }
        /// <summary>
        ///  需要验证码事件
        /// </summary>
        void FrmMain_eventNeedImage()
        {
            ImageCode();
        }
        #endregion

        //提交
        /// <summary>
        /// 提交
        /// </summary>
        private void Submit()
        {
            if (qquser.IsNeedCode)
            {
                if (this.txtCode.Text.Trim().Length != 4)
                {
                    MessageBox.Show("4个验证码,好不好");
                    return;
                }
            }
            qquser.VerifyCode = this.txtCode.Text.Trim();
            ChangeSubmitButtonState(false);
            this.txtCode.Text = string.Empty;
            Thread th = new Thread(new ThreadStart(QQUpdate));
            th.Start();
        }

        //开始 修改
        /// <summary>
        /// 开始 修改
        /// </summary>
        private void QQUpdate()
        {
            if (qquser.GTK <= 0)
            {
                string strCookies = httpClient.Cookies.GetCookieHeader(new Uri(VoteUrl.ADRESS_QZONE));
                qquser.GTK = GetGTK(new MatchData("; skey=", ";", strCookies).Match(RegexOptions.None));
            }
            switch (qquser.UpdateState)
            {
                case UpdateState.昵称:
                    try
                    {
                        UpdateQQNiceName();
                    }
                    catch (Exception ex)
                    {
                        this.SetText("error:修改QQ昵称错误");
                    }
                    ChangeSubmitButtonState(true);
                    break;
                case UpdateState.空间名称:
                    try
                    {
                        UpdateQQQZoneName();
                    }
                    catch (Exception)
                    {
                        this.SetText("error:修改QQ空间名称错误");
                    }
                    ChangeSubmitButtonState(true);
                    break;
                case UpdateState.个性签名:
                    try
                    {
                        UpdateQQSignature();
                    }
                    catch (Exception)
                    {
                        this.SetText("个性签名发表失败");
                    }
                    ChangeSubmitButtonState(true);
                    break;
                case UpdateState.输出信息:
                    try
                    {
                        PrintQQNnameSigSpace();
                    }
                    catch (Exception)
                    {
                        this.SetText("error:获取QQ相关信息失败");
                    }
                    break;
                default:
                    break;
            }
        }

        //您的QQ昵称,QQ签名,QQ空间名称,将修改为家族统一的格式。

        //修改 QQ昵称
        /// <summary>
        /// 修改 QQ昵称
        /// </summary>
        private void UpdateQQNiceName()
        {
            //string url = string.Format("http://{0}.qzone.qq.com/", qquser.QQAccount);

            string url2_2 = string.Format("http://base.s3.qzone.qq.com/cgi-bin/user/cgi_userinfo_get_all?uin={0}&vuin={0}&rd=0.5263281290315378&g_tk={1}", qquser.QQAccount, qquser.GTK);
            httpClient.Encoding = Encoding.UTF8;
            //string resultQzongIndex = httpClient.DownloadString(url);
            //string resultInfo = httpClient.DownloadString(url2_2);

            //#region 获取 国家 省 市

            ////国家，省份，城市 的地址
            ////http://ctc.qzs.qq.com/qzone/address/add_select.js
            ////http://imgcache.qq.com/qzone/address/country.js
            ////其它国家获取城市的地址
            ////"http://ctc.qzs.qq.com/qzone/address/AUS.js

            //if (qquser.DictionaryCountry == null)
            //{
            //    string countrys = httpClient.DownloadString("http://imgcache.qq.com/qzone/address/country.js");
            //    MatchData md = new MatchData("'(.|\n)*?': ", "'(.|\n)*?'", countrys);
            //    Match[] match = md.Matches(RegexOptions.None);
            //    qquser.DictionaryCountry = new Dictionary<string, string>(match.Length);
            //    for (int i = 0; i < match.Length; i++)
            //    {

            //        string resultReplace = Regex.Replace(match[i].Value, "('|'| )", "");
            //        string[] s = resultReplace.Split(':');
            //        if (s.Length >= 2)
            //        {
            //            qquser.DictionaryCountry.Add(s[0], s[1]);
            //        }

            //    }
            //}
            //string resultInfo = httpClient.DownloadString(url2_2);
            //qquser.Desc = new MatchData("\"desc\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None);
            //string country = new MatchData("\"country\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None);

            //try
            //{
            //    if (string.IsNullOrEmpty(country))
            //    {
            //        string proOrCity = httpClient.DownloadString("http://ctc.qzs.qq.com/qzone/address/" + qquser.DictionaryCountry[country] + ".js");

            //    }

            //}
            //catch (Exception)
            //{
            //    //this.SetText("error:获取省市错误");
            //}
            //#endregion

            //#region  cgi_userinfo_get_all 获取用户相关信息 查看

            ////            _Callback(
            ////{"uin":404313364,
            ////"nickname":"Ｓmile．llkkkjiml飞啊子",
            ////"spacename":"◤Ｓmile　Lang syne　¨　冰￥◢",
            ////"desc":"",
            ////"signature":"[ft=,,Webdings][ft=,6,][ft=#f7941d,,][ft=#00a99e,,][ft=#00aeef,,]sssdss[/ft][/ft][/ft][/ft][/ft]\n\n",
            ////"avatar":"",
            ////"sex_type":0,
            ////"sex":2,
            ////"animalsign_type":0,
            ////"constellation_type":0,
            ////"constellation":2,
            ////"age_type":0,
            ////"age":22,
            ////"islunar":0,
            ////"birthday_type":0,
            ////"birthyear":1989,
            ////"birthday":"05-29",
            ////"bloodtype":5,
            ////"address_type":0,
            ////"country":"中国",
            ////"province":"湖南",
            ////"city":"株洲",
            ////"home_type":0,
            ////"hco":"中国",
            ////"hp":"湖南",
            ////"hc":"株洲",
            ////"marriage":1,
            ////"career":"不知",
            ////"company":"我要飞有限公司",
            ////"cco":"中国",
            ////"cp":"陕西",
            ////"cc":"宝鸡",
            ////"cb":"aaxcvbnmaa详细地址",
            ////"interest":""});

            //#endregion

            //#region 提交修改用户信息 相关参数查看
            ////string aa = "nickname=sgwgsgwga&sex=2&birthday=1989-05-29&province=43&city=2&country=1&marriage=-1&bloodtype=1&hp=0&hc=0&hco=0&career=%E4%B8%8D%E7%9F%A5&company=&cp=0&cc=0&cb=aaxcvbnm&cco=0&islunar=0&mb=1027&uin=404313364&pageindex=1";
            ////"nickname=%EF%BC%B3mile%EF%BC%8Ellkkkjiml%E9%A3%9E%E5%95%8A%E5%AD%90& //昵称
            ////sex=2& //性别
            ////birthday=1989-05-29& //生日
            ////province=43& //现居地 省
            ////city=2&       //现居地 市
            ////country=1& //现居地 国家
            ////marriage=1&  //婚姻
            ////bloodtype=5& // 血型
            ////hp=43&   // 故乡 省
            ////hc=2&   //故乡 市 
            ////hco=1& //故乡 国
            ////career=%E4%B8%8D%E7%9F%A5& //职业
            ////company=%E6%88%91%E8%A6%81%E9%A3%9E%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8& //公司名称
            ////cp=61& //  公司所在地 省
            ////cc=3&  //  公司所在地 市
            ////cb=aaxcvbnmaa%E8%AF%A6%E7%BB%86%E5%9C%B0%E5%9D%80& //详细资料
            ////cco=1& //公司所在地 国家
            ////islunar=0& //阴历或阳历
            ////mb=1& //
            ////uin=404313364&
            ////pageindex=1"
            //#endregion


            //#region 提交参数 IDictionary<string, string>
            //IDictionary<string, string> dictionary = new Dictionary<string, string>();
            //dictionary.Add("nickname", qquser.Nickname);
            //dictionary.Add("sex", new MatchData("\"sex\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("birthday", new MatchData("\"birthyear\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None) + "-" + new MatchData("\"birthday\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("province", new MatchData("\"province\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("city", new MatchData("\"city\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("country", "1");
            //dictionary.Add("city", "8");
            //dictionary.Add("province", "34");
            //dictionary.Add("hp", "34");
            //dictionary.Add("hc", "8");
            //dictionary.Add("hco", "1");

            //dictionary.Add("cp", "34");
            //dictionary.Add("cc", "8");
            //dictionary.Add("cco", "1");

            //dictionary.Add("marriage", new MatchData("\"marriage\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("bloodtype", new MatchData("\"bloodtype\":(\"?),", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("hp", new MatchData("\"hp\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("hc", new MatchData("\"hc\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("hco", new MatchData("\"hco\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("career", new MatchData("\"career\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("company", new MatchData("\"company\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("cp", new MatchData("\"cp\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("cc", new MatchData("\"cc\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////职位
            //dictionary.Add("cb", new MatchData("\"cb\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            ////dictionary.Add("cco", new MatchData("\"cco\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("islunar", new MatchData("\"islunar\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("mb", "1");
            //dictionary.Add("uin", new MatchData("\"uin\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None));
            //dictionary.Add("pageindex", "1");
            //#endregion

            // PostData pd = new PostData(dictionary);
            IDictionary<string, string> dictionary = new Dictionary<string, string>();
            PostData pd = new PostData(dictionary);
            dictionary.Add("nickname", qquser.Nickname);
            dictionary.Add("islunar", "0");
            dictionary.Add("mb", "1");
            dictionary.Add("uin", qquser.QQAccount);
            dictionary.Add("pageindex", "1");
            if (qquser.IsNeedCode)
            {
                dictionary.Add("verifycode", qquser.VerifyCode);
                qquser.IsNeedCode = false;
            }
            string resultUpdate = httpClient.PostData(VoteUrl.AdressVoteSend + "?g_tk=" + qquser.GTK, pd.ToString(), Encoding.UTF8, Encoding.UTF8);
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head> <body><script type="text/javascript">document.domain="qq.com"; frameElement.callback( {"ret":"error","type":"verify","msg":"验证码错误"} );</script></body></html>
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head> <body><script type="text/javascript">document.domain="qq.com"; frameElement.callback( {"ret":"error","type":"needverify","msg":"需要验证码"} );</script></body></html>
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head> <body><script type="text/javascript">document.domain="qq.com"; frameElement.callback( {"ret":"succ","type":"","msg":"修改成功."} );</script></body></html>
            if (resultUpdate.Contains("需要验证码"))
            {
                qquser.IsNeedCode = true;
                this.SetText("修改昵称需要验证码。");
                if (eventNeedImage != null)
                {
                    this.eventNeedImage();
                }
                return;
            }
            else if (resultUpdate.Contains("验证码错误"))
            {
                qquser.IsNeedCode = true;
                this.SetText("修改昵称验证码错误。");
                if (eventNeedImage != null)
                {
                    this.eventNeedImage();
                }
                return;
            }
            else if (resultUpdate.Contains("修改成功"))
            {
                this.SetText("QQ昵称修改成功。");
                qquser.UpdateState = UpdateState.空间名称;
                Submit();
            }
            else
            {
                qquser.IsNeedCode = true;
                this.SetText("QQ昵称修改,失败.");
                if (eventNeedImage != null)
                {
                    this.eventNeedImage();
                }
            }
        }

        //修改 QQ签名
        /// <summary>
        /// 修改 QQ签名
        /// </summary>
        private void UpdateQQSignature()
        {
            #region 相关参数抓取
            //http://taotao.qq.com/cgi-bin/emotion_cgi_signset?g_tk=934962045 地址
            //uin=404313364&qqsign=1&hostuin=404313364&g_tk=934962045 同步
            //同步 结果
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><script type="text/javascript"> document.domain="qq.com"; frameElement.callback({"result":{"code":0,"msg":"","now":1295262373,"smoothpolicy":{"comsw.disable_soso_search":0,"l1sw.read_first_cache_only":0,"l2sw.dont_get_reply_cmt":0,"l2sw.mixsvr_frdnum_per_time":50,"l3sw.hide_reply_cmt":0,"l4sw.read_tdb_only":0,"l5sw.read_cache_only":0}}}); </script></body></html>
            //uin=404313364&qqsign=0&hostuin=404313364&g_tk=934962045 不同步
            //不同步返回结果
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><script type="text/javascript"> document.domain="qq.com"; frameElement.callback({"result":{"code":0,"msg":"","now":1295262755,"smoothpolicy":{"comsw.disable_soso_search":0,"l1sw.read_first_cache_only":0,"l2sw.dont_get_reply_cmt":0,"l2sw.mixsvr_frdnum_per_time":50,"l3sw.hide_reply_cmt":0,"l4sw.read_tdb_only":0,"l5sw.read_cache_only":0}}}); </script></body></html>

            //http://taotao.qq.com/cgi-bin/emotion_cgi_firstutf8?uin=404313364&g_tk=934962045 获取个性签名地址

            // result
            //            callback({
            //   "archive" : 1,
            //   "items" : [
            //      {
            //         "archive" : -1,
            //         "comment" : 0,
            //         "effect" : -1,
            //         "expression" : 0,
            //         "id" : "14551918c41b344d57ac0100",
            //         "pubDate" : "2011-01-17 18:36:50",
            //         "pubTime" : "约36分钟前",
            //         "title" : "笑家官网 www.520xiao.com　论坛 www.592xiao.com"
            //      }
            //   ],
            //   "result" : {
            //      "smoothpolicy" : {
            //         "comsw.disable_soso_search" : 0,
            //         "l1sw.read_first_cache_only" : 0,
            //         "l2sw.dont_get_reply_cmt" : 0,
            //         "l2sw.mixsvr_frdnum_per_time" : 50,
            //         "l3sw.hide_reply_cmt" : 0,
            //         "l4sw.read_tdb_only" : 0,
            //         "l5sw.read_cache_only" : 0
            //      }
            //   }
            //}
            //)
            //签名地址
            //http://taotao.qq.com/cgi-bin/emotion_cgi_publish?g_tk=934962045
            //参数
            //con=qmhttp%3A%2F%2Ftaotao.qq.com%2Fcgi-bin%2Femotion_cgi_firstutf8%3F%E6%88%91%E6%9D%A5%E5%95%A6%E5%95%A6%E5%95%A6%E3%80%82&who=1&hostuin=404313364&g_tk=934962045
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><script type="text/javascript"> document.domain="qq.com"; frameElement.callback({"err":{"code":1012},needVerify:0,"result":{"code":1012,"msg":"","now":1295268000},"richinfo":null,"tid":null,feedinfo:null}); </script></body></html>

            //http://taotao.qq.com/vc1/qz_comonpublish/def 个性签名
            //con=qm%E7%AC%91%E5%AE%B6%E5%AE%98%E7%BD%91%20www.520xiao.com
            //%E3%%80%E8%AE%BA%E5%9D80%9B%20www.592xiao.com&
            //head=0&otype=json&operuin=&g_tk=1969055608
            //<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><script type="text/javascript">document.domain="qq.com";frameElement.callback({"ret":0,"tid":"145519185139354da81f0500","msg":"ok"});</script></body></html>
            #endregion
            //设置同步与不同步地址
            string url = string.Format("http://taotao.qq.com/cgi-bin/emotion_cgi_signset?g_tk={0}", qquser.GTK);
            string url2 = string.Format("http://taotao.qq.com/cgi-bin/emotion_cgi_publish?g_tk={0}", qquser.GTK);
            string url3 = string.Format("http://taotao.qq.com/cgi-bin/emotion_cgi_firstutf8?uin={0}&g_tk={1}", qquser.QQAccount, qquser.GTK);
            string url4 = string.Format("http://taotao.qq.com/vc1/qz_comonpublish/def");
            //同步结果
            string resultUpdateQqsign1 = httpClient.PostData(url, string.Format("uin={0}&qqsign=1&hostuin={0}&g_tk={1}", qquser.QQAccount, qquser.GTK), Encoding.UTF8, Encoding.UTF8);

            IDictionary<string, string> dictionary = new Dictionary<string, string>();
            PostData pd = new PostData(dictionary);
            dictionary.Add("con", qquser.Con);
            dictionary.Add("who", "1");
            dictionary.Add("hostuin", qquser.QQAccount);
            dictionary.Add("g_tk", qquser.GTK.ToString());
            string aa= httpClient.DownloadString("http://pingfore.qq.com/pingd?dm=taotaoact.qzone.qq.com&url=app_publish&rdm=-&rurl=-&pvid=712660610&scr=-&scl=-&lang=-&java=1&cc=-&pf=-&tz=-8&ct=-&vs=3.3&rnd=0.047832030605392595");
            string resultUpdateCon = httpClient.PostData(url2, pd.ToString(), Encoding.UTF8, Encoding.UTF8);
            string resultIsdsPeed= httpClient.DownloadString("http://isdspeed.qq.com/cgi-bin/v.cgi?flag1=400015&flag2=1&flag3=99&1=1&2=360");
             string resultCon = httpClient.DownloadString(url3);

            //"title" : "笑家官网 www.520xiao.com　论坛 www.592xiao.com"
            string resultMatch = new MatchData("\"title\" : \"", "\"", resultCon).Match(RegexOptions.None);
            VoteLog.AddResult("result.fei", "uin=" + qquser.QQAccount + "&con1=" + resultUpdateCon + "&con2=" + resultCon);

            dictionary.Clear();
            dictionary.Add("con", qquser.Con);
            dictionary.Add("head", "0");
            dictionary.Add("otype", "json");
            dictionary.Add("operuin", "");
            dictionary.Add("g_tk", qquser.GTK.ToString());
            string resultUpdateCon2 = httpClient.PostData(url4, pd.ToString(), Encoding.UTF8, Encoding.UTF8);
            //不同步结果
            //string resultUpdateQqsign0 = httpClient.PostData(url, string.Format("uin={0}&qqsign=0&hostuin={0}&g_tk={1}", qquser.QQAccount, qquser.GTK), Encoding.UTF8, Encoding.UTF8);
           
            if (resultUpdateCon2.Contains("\"msg\":\"ok\""))
            {
                this.SetText("个性签名发表成功。");
                qquser.UpdateState = UpdateState.输出信息;
                Submit();
            }
            else
            {
                this.SetText("个性签名.....很抱歉，当前使用的人数过多，请休息一会儿再来.....");
                qquser.Con = null;
                qquser.UpdateState = UpdateState.输出信息;
                Submit();
            }
        }

        //QQ空间名称 签名档
        /// <summary>
        /// QQ空间名称 签名档
        /// </summary>
        private void UpdateQQQZoneName()
        {
            //http://w.qzone.qq.com/cgi-bin/user/cgi_apply_updateuserinfo_new?g_tk=547293539
            IDictionary<string, string> dictionary = new Dictionary<string, string>();

            dictionary.Add("spacename", qquser.Spacename);
            dictionary.Add("dsc", qquser.Desc);
           // dictionary.Add("signature", qquser.Signature);
            dictionary.Add("mb", "2048");
            dictionary.Add("uin", qquser.QQAccount);
            dictionary.Add("pageindex", "3");
            if (qquser.IsNeedCode)
            {
                dictionary.Add("verifycode", qquser.VerifyCode);
                qquser.IsNeedCode = false;
            }
            PostData pd = new PostData(dictionary);
            //string postData = "spacename=qaz%E9%A3%9E%E5%95%8A%E5%AD%9023&desc=...............%EF%BC%8C%E9%A3%9E%E5%95%8A%E5%AD%90%E6%88%91%E4%BB%AC%E6%98%AF%E6%B0%B8%E8%BF%9C%E5%B9%B8%E7%A6%8F%E5%BF%AB%E4%B9%90%E7%9A%84%E5%A5%BD%E6%9C%8B%E5%8F%8B%E3%80%82&signature=mkoikdfghjkijnhbtyuhnjkil%3B%2Ckgfhjkl%3B&";
            string resultUpdate = httpClient.PostData(VoteUrl.AdressVoteSend + "?g_tk=" + qquser.GTK, pd.ToString(), Encoding.UTF8, Encoding.UTF8);
            //this.webBrowser1.ScriptErrorsSuppressed = true;
            if (resultUpdate.Contains("需要验证码"))
            {
                qquser.IsNeedCode = true;
                this.SetText("修改空间名称需要验证码。");
                if (eventNeedImage != null)
                {
                    this.eventNeedImage();
                }
                return;
            }
            else if (resultUpdate.Contains("验证码错误"))
            {
                qquser.IsNeedCode = true;
                this.SetText("修改空间名称验证码错误。");
                if (eventNeedImage != null)
                {
                    this.eventNeedImage();
                }
                return;
            }
            else if (resultUpdate.Contains("修改成功"))
            {
                this.SetText("QQ空间名称修改成功");
                qquser.UpdateState = UpdateState.个性签名;
                Submit();

            }
            else
            {
                qquser.IsNeedCode = true;
                this.SetText("QQ空间名称,失败.");
                if (eventNeedImage != null)
                {
                    this.eventNeedImage();
                }
            }
        }

        //输出QQ昵称
        /// <summary>
        /// 输出QQ昵称
        /// </summary>
        private void PrintQQNnameSigSpace()
        {
            string url2_2 = string.Format("http://base.s3.qzone.qq.com/cgi-bin/user/cgi_userinfo_get_all?uin={0}&vuin={0}&rd=0.5263281290315378&g_tk={1}", qquser.QQAccount, qquser.GTK);
            httpClient.Encoding = Encoding.UTF8;
            string resultInfo = httpClient.DownloadString(url2_2);
            string nicename = new MatchData("\"nickname\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None);
            string spacename = new MatchData("\"spacename\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None);
            string signature = new MatchData("\"signature\":(\"?)", "(\"?),", resultInfo).Match(RegexOptions.None);
            string formatInfo = string.Format("{1}当前信息如下:{0}QQ昵称:{2};{0}QQ个性签名:{3}{0}空间名称:{4};{0}", Environment.NewLine, qquser.QQAccount, nicename, string.IsNullOrEmpty(qquser.Con)?"":qquser.Con, spacename);
            this.SetText(formatInfo);
            if (this.eventChangeTab != null)
            {
                this.eventChangeTab(true);
            }

        }

        //QQ空间的g_tk算法
        /// <summary>
        /// QQ空间的g_tk算法 
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private int GetGTK(string skey)
        {
            var hash = 5381;
            if (!string.IsNullOrEmpty(skey))
            {
                for (int i = 0, len = skey.Length; i < len; ++i)
                {
                    hash += (hash << 5) + (char)skey[i];
                }
            }
            return hash & 0x7fffffff;
        }

        //验证码
        /// <summary>
        /// 验证码
        /// </summary>
        private void ImageCode()
        {
            try
            {
                string imageName = "szz.jpg";
                if (File.Exists(imageName))
                {
                    File.Delete(imageName);
                }
                httpClient.DownloadFile(new Uri(VoteUrl.ADRESS_IMAGE_CODE + "?r=" + DateTime.Now), imageName);
                FileInfo fi = new FileInfo(imageName);
                if (fi != null)
                {
                    fi.Attributes = FileAttributes.Hidden;

                }
                pbImage.LoadAsync(imageName);
            }
            catch (Exception)
            {
                this.SetText("error:获取验证码失败");
            }
        }

        //计算 字符串的 字节长度
        /// <summary>
        /// 计算 字符串的 字节长度
        /// 汉字，中文状态下的字符， 占2 个
        /// 字母，数字 占1个
        /// </summary>
        /// <param name="strContent"></param>
        /// <returns></returns>
        public int Length(string strContent)
        {
            return System.Text.Encoding.Default.GetByteCount(strContent);
        }

        //日志
        /// <summary>
        /// 日志
        /// </summary>
        private void Log()
        {
            if (this.rtbResult.InvokeRequired)
            {
                LogCallback set = new LogCallback(Log);
                this.Invoke(set);
            }
            else
            {
                VoteLog.AddResult("result.fei", this.rtbResult.Text);
                this.rtbResult.Clear();
            }
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Log();
        }
    }
}

